The Collatz Conjecture

During the 1930's, Lothar Collatz at the University of Hamburg studied the function

 

  1. Write a C++ program with will take a natural number input, n, and output to the console the sequence of iterates
    . Here the superscript k indicates the number of times the function is recycled so that, for instance,

.

Design your code so that n is an unsigned long int and so that you can input the initial value of n from the console. Use an if/else if/else structure to control the flow of the algorithm. Use a "while(true)" loop with "cin.get()" so that the numbers are displayed in the console window at a rate of one output number per keypress.

Submit your code as XX_Collatz01.cpp where “XX” are your initials.

  1. Have while loop terminate if n exceeds 1,000,000,000. Is this too high, not high enough? If so, find the best upper limit for n.

    Write your answer as a text file.  Save your answer to this question as XX_Collatz02.txt

  2. What happens with initial values for n less than 8? That is, what sequences result for initial values 1,2,3,4,5,6,7?

    Save your answer to this question as XX_Collatz03.txt

  3. If the initial value n=8 is used, what are the last six entries on the console when the program terminates?

    Save your answer to this question as XX_Colaltz04.txt

Studies such as Collatz' may be said to have led to B. Thwaite's discovery, in 1952, of the "3x+1 problem", which is concerned with iterates of the function

 

5.      Write a C++ program with will take a natural number input, n, and output to the console the sequence of iterates .
Save this program as XX_Collatz05.cpp.

6.      Experiment with various different initial values. Describe the results of your experimentation.